- content_for :head do
  = stylesheet_link_tag     'multibox'
  = javascript_include_tag  'mootools'
  = javascript_include_tag  'multibox'
  = javascript_include_tag  'overlay'
  %script{:type => "text/javascript"}
    ="  var photo_box = {};"
    ="  window.addEvent('domready', function(){"
    ="      box = new MultiBox('mb', {descClassName: 'popup_box_content'});"
    ="  });"
%h2.page_title Gallery Approvals
%p 
  This is a listing of the items in
  %a{:href => gallery_url(@gallery), :title => "Go back to #{@gallery.name}"}= "\"#{@gallery.name}\""
  that have been approved or declined.
  - if @gallery.items_needing_review.length > 1
    You can always
    %a{:href => gallery_url(@gallery), :title => "Go back to #{@gallery.name}"}go back
    and review more photos since there are still some items here which require your attention.
%table.gallery_approvals
  %tr
    %td.split_width
      %table
        %tr
          %td{:colspan => 2} These items have been reviewed:
        - if @gallery.approvals.empty?
          %tr
            %td
              No items have been reviewed at this time.
              %a{:href => gallery_url(@gallery), :title => "#{@gallery.name}"} Click here
              to return and review photos in this gallery.
        - else
          - form_for @gallery do |form|
            %input{:type => "hidden", :value => (@gallery.private? ? "1" : "0" ), :name => "gallery[private]"}
            %input{:type => "hidden", :value => (@gallery.invisible? ? "1" : "0" ), :name => "gallery[invisible]"}
            %input{:type => "hidden", :value => (@gallery.for_proofing? ? "1" : "0" ), :name => "gallery[for_proofing]"}
            %input{:type => "hidden", :value => (@gallery.is_approved? ? "1" : "0" ), :name => "gallery[is_approved]"}
            %input{:type => "hidden", :value => (@gallery.photo ? @gallery.photo.id : nil), :name => "gallery[photo_id]"}
            - @gallery.users.each do |user|
              %input{:type => "hidden", :value => user.id, :name => "gallery[user_ids][]"}
            - @gallery.pages.each do |page|
              %input{:type => "hidden", :value => page.id, :name => "gallery[page_ids][]"}
            - @gallery.photos.each do |photo|
              %input{:type => "hidden", :value => photo.id, :name => "gallery[photo_ids][]"}
              - if photo.approved_in?(@gallery) || photo.declined_in?(@gallery)
                %input{:type => "hidden", :value => photo.id, :name => "gallery[approval_items][#{photo.approval_in(@gallery).id}][photo_id][]"}
                %tr.approvals
                  %td.photo
                    %table.photo{:class => (photo.approved_in?(@gallery) ? "photo_approved" : ("photo_declined" if photo.declined_in?(@gallery)))}
                      %tr
                        %td.photo
                          %a.mb{:href => photo.public_filename(:screen), :rel => "width:800,height:600", :id => "photo_#{photo.id.to_s}", :title => (photo.caption ? photo.caption : photo.filename), :alt => (photo.caption ? photo.caption : photo.filename)}
                            %img.photo_thumb{:src => photo.public_filename(:thumb), :title => (photo.caption ? photo.caption : photo.filename), :alt => (photo.caption ? photo.caption : photo.filename)}
                          %div{:class => "popup_box_content photo_#{photo.id.to_s}", :id => "photo_#{photo.id.to_s}"}
                  %td.appoval_info
                    %table.approval_info
                      %tr
                        %td.field_title Status:
                        %td.field
                          - if (params[:process] == "confirm") || @gallery.is_approved?
                            - if photo.approved_in?(@gallery)
                              %span.approved approved
                            - elsif photo.declined_in?(@gallery)
                              %span.declined declined
                          - else
                            %select{:name => "gallery[approval_items][#{photo.approval_in(@gallery).id}][approval]"}
                              %option{:value => "approve", :selected => ('selected' if photo.approved_in?(@gallery))} approved
                              %option{:value => "decline", :selected => ('selected' if photo.declined_in?(@gallery))} declined
                      %tr
                        %td.field_title On:
                        %td.field= photo.approval_in(@gallery).updated_at.strftime("%m/%d/%y at %I:%M %p")
            - @gallery.videos.each do |video|
              %input{:type => "hidden", :value => video.id, :name => "gallery[video_ids][]"}
              - if video.approved_in?(@gallery) || video.declined_in?(@gallery)
                %input{:type => "hidden", :value => video.id, :name => "gallery[approval_items][#{video.approval_in(@gallery).id}][video_id][]"}
                %tr
                  %td.video
                    %table.video{:class => (video.approved_in?(@gallery) ? "video_approved" : ("video_declined" if video.declined_in?(@gallery)))}
                      %tr
                        %td.video
                          %a.mb{:href => video.public_filename, :rel => "width:853,height:496", :id => "video_#{video.id.to_s}", :title => (video.caption ? video.caption : video.filename), :alt => (video.caption ? video.caption : video.filename)}
                            %img.video_thumb{:src => video.thumbnail, :title => (video.caption ? video.caption : video.filename), :alt => (video.caption ? video.caption : item.filename)}
                          %div{:class => "popup_box_content video_#{video.id.to_s}", :id => "video_#{video.id.to_s}"}
                  %td.appoval_info
                    %table.approval_info
                      %tr
                        %td.field_title Status:
                        %td.field
                          - if @gallery.is_approved?
                            - if video.approved_in?(@gallery)
                              %span.approved approved
                            - elsif video.declined_in?(@gallery)
                              %span.declined declined
                          - else
                            %select{:name => "gallery[approval_items][#{video.approval_in(@gallery).id}][approval]"}
                              %option{:value => "approve", :selected => ('selected' if video.approved_in?(@gallery))} approved
                              %option{:value => "decline", :selected => ('selected' if video.declined_in?(@gallery))} declined
                      %tr
                        %td.field_title On:
                        %td.field= video.approval_in(@gallery).updated_at.strftime("%m/%d/%y at %I:%M %p")
            - unless @gallery.is_approved?
              %tr
                %td
                %td.submit
                  %p 
                    Everything look the way you want it? If so, you are ready to submit these approvals. If not, you can always
                    %a{:href => gallery_approvals_url(@gallery), :title => "Change you approval request"} go back
                    and change the approval request.
                  %p= submit_tag "send approvals"
            - else
              %tr
                %td{:colspan => 3}
                  %p These approvals have been sent to Dan Stewart.
    - unless @gallery.items_needing_review.empty? or @gallery.is_approved?
      %td.unreviewed_items
        %table.unreviewed_items
          %tr
            %td{:colspan => 2} Unreviewed items:
          %tr
            %td
              - @gallery.items_needing_review.each do |item|
                - if item.is_a?(Photo)
                  %table.photo
                    %tr
                      %td.photo
                        %a.mb{:href => item.public_filename(:screen), :rel => "width:800,height:600", :id => "photo_#{item.id.to_s}", :title => (item.caption ? item.caption : item.filename), :alt => (item.caption ? item.caption : item.filename)}
                          %img.photo_thumb{:src => item.public_filename(:thumb), :title => (item.caption ? item.caption : item.filename), :alt => (item.caption ? item.caption : item.filename)}
                        %div{:class => "popup_box_content photo_#{item.id.to_s}", :id => "photo_#{item.id.to_s}"}
                - if item.is_a?(Video)
                  %table.video
                    %tr
                      %td.video
                        %a.mb{:href => item.public_filename, :rel => "width:853,height:496", :id => "video_#{item.id.to_s}", :title => (item.caption ? item.caption : item.filename), :alt => (item.caption ? item.caption : item.filename)}
                          %img.video_thumb{:src => item.thumbnail, :title => (item.caption ? item.caption : item.filename), :alt => (item.caption ? item.caption : item.filename)}
                        %div{:class => "popup_box_content video_#{item.id.to_s}", :id => "video_#{item.id.to_s}"}